#include "stdafx.h"
#include "wf_setrelativezero.h"

#include "pf_snapper.h"
#include "pf_point.h"



WF_SetRelativeZero::WF_SetRelativeZero(PF_Container& container,
        PF_GraphicView& graphicView)
        :PF_PreviewActionInterface("Set the relative Zero",
                           container, graphicView) {}


QAction* WF_SetRelativeZero::createGUIAction(LX_Define::ActionType /*type*/, QObject* /*parent*/) {
/*      QAction* action = new QAction(tr("Set Relative Zero"), tr("&Set Relative Zero"),
                                  QKeySequence(), NULL); */
    QAction* action = new QAction(tr("Set Relative Zero"), NULL);
    //action->zetStatusTip(tr("Set position of the Relative Zero point"));
	action->setIcon(QIcon(":/extui/relzeromove.png"));
    return action;
}


void WF_SetRelativeZero::trigger() {
    bool wasLocked = graphicView->isRelativeZeroLocked();
    if (pt.valid) {
        graphicView->lockRelativeZero(false);
        graphicView->moveRelativeZero(pt);
        graphicView->lockRelativeZero(wasLocked);
    }
    finish();
}



void WF_SetRelativeZero::mouseMoveEvent(PF_MouseEvent* e) {
    snapPoint(e);
}



void WF_SetRelativeZero::mouseReleaseEvent(PF_MouseEvent* e) {
    if (e->button()==Qt::RightButton) {
        init(getStatus()-1);
    } else {
        PF_CoordinateEvent ce(snapPoint(e));
        coordinateEvent(&ce);
    }
}



void WF_SetRelativeZero::coordinateEvent(PF_CoordinateEvent* e) {
    if (e==NULL) {
        return;
    }

    pt = e->getCoordinate();
    trigger();
}



void WF_SetRelativeZero::updateMouseButtonHints() {
    switch (getStatus()) {
    case 0:
        PF_DIALOGFACTORY->updateMouseWidget(tr("Set relative Zero"), tr("Cancel"));
        break;
    default:
        PF_DIALOGFACTORY->updateMouseWidget("", "");
        break;
    }
}



void WF_SetRelativeZero::updateMouseCursor() {
    graphicView->setMouseCursor(LX_Define::CadCursor);
}



void WF_SetRelativeZero::updateToolBar() {
    if (!isFinished()) {
        PF_DIALOGFACTORY->requestToolBar(LX_Define::ToolBarSnap);
    } else {
        PF_DIALOGFACTORY->requestToolBar(LX_Define::ToolBarSnap);
    }
}

// EOF
